<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="登记日期" prop="aftOrderDate">
        <el-date-picker clearable
          v-model="queryParams.aftOrderDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择登记日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单编号" prop="aftOrderCode">
        <el-input
          v-model="queryParams.aftOrderCode"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="售后编号" prop="aftCode">
        <el-input
          v-model="queryParams.aftCode"
          placeholder="请输入售后编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="售后申请日期" prop="aftApplyTime">
        <el-date-picker clearable
          v-model="queryParams.aftApplyTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择售后申请日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="商品名称" prop="aftGoodName">
        <el-input
          v-model="queryParams.aftGoodName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发货单号" prop="aftSendCode">
        <el-input
          v-model="queryParams.aftSendCode"
          placeholder="请输入发货物流单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退货单号" prop="aftReturnCode">
        <el-input
          v-model="queryParams.aftReturnCode"
          placeholder="请输入退货物流单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退货发货时间" prop="aftReturnTime">
        <el-date-picker clearable
          v-model="queryParams.aftReturnTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择退货发货时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="退货物流状态" prop="aftReturnStatus">
        <el-select v-model="queryParams.aftReturnStatus" placeholder="请选择退货物流状态" clearable>
          <el-option
            v-for="dict in dict.type.aft_return_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="售后类型" prop="aftKind">
        <el-select v-model="queryParams.aftKind" placeholder="请选择售后类型" clearable>
          <el-option
            v-for="dict in dict.type.aft_kind"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="售后标签" prop="aftTab">
        <el-select v-model="queryParams.aftTab" placeholder="请选择售后标签" clearable>
          <el-option
            v-for="dict in dict.type.aft_tab"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="售后状态" prop="aftStauts">
        <el-select v-model="queryParams.aftStauts" placeholder="请选择售后状态" clearable>
          <el-option
            v-for="dict in dict.type.aft_stauts"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商家退货地址" prop="aftReturnAddress">
        <el-select v-model="queryParams.aftReturnAddress" placeholder="请选择商家退货地址" clearable>
          <el-option
            v-for="dict in dict.type.return_add"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mes:aft:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes:aft:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mes:aft:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:user:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes:aft:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" prop="aftId" /> -->
      <el-table-column label="登记日期" align="center" prop="aftOrderDate" width="80">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.aftOrderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" align="center" prop="aftOrderCode" width="120"/>
      <el-table-column label="售后编号" align="center" prop="aftCode" width="120"/>
      <el-table-column label="售后申请时间" align="center" prop="aftApplyTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.aftApplyTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="商品名称" align="center" prop="aftGoodName" width="120"/>
      <el-table-column label="应付金额" align="center" prop="aftPay" />
      <el-table-column label="售后原因" align="center" prop="aftReason" />
      <!-- <el-table-column label="发货物流单号" align="center" prop="aftSendCode" v-bind:title="tooltip" @mouseover="fetchData"/> -->
      <el-table-column label="发货物流单号" align="center" prop="aftSendCode">
        <template slot-scope="scope">
          <!-- v-bind:title="tooltip" @mouseover="fetchData('send',scope.row)" -->
          <span >
          {{scope.row.aftSendCode}}
          <p @click="fetchData('send',scope.row)" style="color:blue;cursor: pointer;" ref="myLink"
          >点击查看</p>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="商家退货地址" align="center" prop="aftReturnAddress">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.return_add" :value="scope.row.aftReturnAddress"/>
        </template>
      </el-table-column>
      <el-table-column label="退货物流单号" align="center" prop="aftReturnCode">
        <template slot-scope="scope">
          <span>
          <!--  v-bind:title="tooltip" @mouseover="fetchData('return',scope.row)" -->
          {{scope.row.aftReturnCode}}
          <p @click="fetchData('return',scope.row)" style="color:blue;cursor: pointer;" ref="myLink"
          >点击查看</p>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="退货发货时间" align="center" prop="aftReturnTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.aftReturnTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退货物流状态" align="center" prop="aftReturnStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aft_return_status" :value="scope.row.aftReturnStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="售后类型" align="center" prop="aftKind">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aft_kind" :value="scope.row.aftKind"/>
        </template>
      </el-table-column>
      <el-table-column label="实际退款金额" align="center" prop="aftReturnPay" />
      <el-table-column label="补偿金额" align="center" prop="aftCompensatePay" />
      <el-table-column label="应退货数量/盒" align="center" prop="aftReturnNum" />
      <el-table-column label="实际收到/盒" align="center" prop="aftReturnPutNum" />
      <el-table-column label="售后标签" align="center" prop="aftTab" width="150">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aft_tab" :value="scope.row.aftTab"/>
        </template>
      </el-table-column>
      <el-table-column label="售后备注" align="center" prop="aftRemark" />
      <el-table-column label="售后状态" align="center" prop="aftStauts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aft_stauts" :value="scope.row.aftStauts"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mes:aft:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mes:aft:order:remove']"
          >删除</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改售后列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row >
          <el-col :span="12">
           <el-form-item label="登记日期" prop="aftOrderDate" >
             <el-date-picker clearable
               v-model="form.aftOrderDate"
               type="date"
               value-format="yyyy-MM-dd"
               placeholder="请选择登记日期" v-if="optType == 'add'">
             </el-date-picker>
             <el-date-picker clearable
               v-model="form.aftOrderDate"
               type="date"
               value-format="yyyy-MM-dd"
               placeholder="请选择登记日期" disabled  v-else>
             </el-date-picker>
           </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="aftOrderCode">
              <el-input v-model="form.aftOrderCode" placeholder="请输入订单编号"  v-if="optType == 'add'"/>
              <el-input v-model="form.aftOrderCode" disabled  v-else/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row >
          <el-col :span="12">
            <el-form-item label="售后编号" prop="aftCode">
              <el-input v-model="form.aftCode" placeholder="请输入售后编号" v-if="optType == 'add'"/>
              <el-input v-model="form.aftCode" disabled  v-else/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="售后申请日期" prop="aftApplyTime">
              <el-date-picker clearable
                v-model="form.aftApplyTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择售后申请日期"v-if="optType == 'add'">
              </el-date-picker>
              <el-input v-model="form.aftApplyTime" disabled  v-else/>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row >
          <el-col :span="8">
            <el-form-item label="商品名称" prop="aftGoodName">
              <el-input v-model="form.aftGoodName" placeholder="请输入商品名称" v-if="optType == 'add'"/>
              <el-input v-model="form.aftGoodName" disabled  v-else/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应付金额" prop="aftPay">
              <el-input v-model="form.aftPay" placeholder="请输入应付金额" v-if="optType == 'add'"/>
              <el-input v-model="form.aftPay" disabled  v-else/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="售后原因" prop="aftReason">
              <el-input v-model="form.aftReason" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row >
          <el-col :span="8">
            <el-form-item label="发货物流公司" prop="aftSendCom">
              <el-select v-model="form.aftSendCom" placeholder="请选择发货物流公司"  v-if="optType == 'add'">
                <el-option
                  v-for="dict in dict.type.express_com"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
              <el-select v-model="form.aftSendCom" placeholder="请选择发货物流公司" disabled v-else>
                <el-option
                  v-for="dict in dict.type.express_com"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发货物流单号" prop="aftSendCode">
              <el-input v-model="form.aftSendCode" placeholder="请输入发货物流单号"  v-if="optType == 'add'"/>
              <el-input v-model="form.aftSendCode" disabled  v-else/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="商家退货地址" prop="aftReturnAddress">
              <el-select v-model="form.aftReturnAddress" placeholder="请选择商家退货地址" >
                <el-option
                  v-for="dict in dict.type.return_add"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>

            </el-form-item>
          </el-col>
        </el-row>

        <el-row >
          <el-col :span="8">
            <el-form-item label="退货物流公司" prop="aftReturnCom">
             <el-select v-model="form.aftReturnCom" placeholder="请选择退货物流公司" v-if="optType == 'add'">
               <el-option
                 v-for="dict in dict.type.express_com"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
               ></el-option>
             </el-select>
             <el-select v-model="form.aftReturnCom" placeholder="请选择退货物流公司" disabled v-else>
               <el-option
                 v-for="dict in dict.type.express_com"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
               ></el-option>
             </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="退货物流单号" prop="aftReturnCode">
              <el-input v-model="form.aftReturnCode" placeholder="请输入退货物流单号" v-if="optType == 'add'"/>
              <el-input v-model="form.aftReturnCode" placeholder="请输入退货物流单号" disabled="" v-else/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="退货发货时间" prop="aftReturnTime" >
              <el-date-picker clearable
                v-model="form.aftReturnTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择退货发货时间" v-if="optType == 'add'">
              </el-date-picker>
              <el-date-picker clearable
                v-model="form.aftReturnTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择退货发货时间" disabled v-else>
              </el-date-picker>

            </el-form-item>

          </el-col>
        </el-row>

        <el-row >
          <el-col :span="8">
            <el-form-item label="退货物流状态" prop="aftReturnStatus">
              <el-select v-model="form.aftReturnStatus" placeholder="请选择退货物流状态" @change="selectAftReturnStatus">
                <el-option
                  v-for="dict in dict.type.aft_return_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="售后类型" prop="aftKind">
              <el-select v-model="form.aftKind" placeholder="请选择售后类型" @change="selectAftKind" v-if="aftKindArr == null || aftKindArr == '' ">
                <el-option
                  v-for="dict in dict.type.aft_kind"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
              <el-select v-model="form.aftKind" placeholder="请选择售后类型" @change="selectAftKind" v-else>
                <el-option
                  v-for="dict in aftKindArr"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="实际退款金额" prop="aftReturnPay">
              <el-input v-model="form.aftReturnPay" placeholder="请输入实际退款金额" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row >
          <el-col :span="8">
            <el-form-item label="补偿金额" prop="aftCompensatePay">
              <el-input v-model="form.aftCompensatePay" placeholder="请输入补偿金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="应退货数量/盒" prop="aftReturnNum">
              <el-input v-model="form.aftReturnNum" placeholder="请输入应退货数量/盒" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="实际收到/盒" prop="aftReturnPutNum">
              <el-input v-model="form.aftReturnPutNum" placeholder="请输入实际收到/盒" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row >
          <el-col :span="8">
            <el-form-item label="售后标签" prop="aftTab">
              <el-select v-model="form.aftTab" placeholder="请选择售后标签">
                <el-option
                  v-for="dict in dict.type.aft_tab"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="售后备注" prop="aftRemark">
              <el-input v-model="form.aftRemark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="售后状态" prop="aftStauts">
              <el-select v-model="form.aftStauts" placeholder="请选择售后状态">
                <el-option
                  v-for="dict in dict.type.aft_stauts"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的售后数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 快递查询对话框 -->
    <el-dialog :title="express.title" :visible.sync="express.open" width="800px" append-to-body>
      <div>
        <pre  style="white-space: normal;">{{express.context}}</pre>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="express.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, getQueryTrackReq } from "@/api/aft/order";
import { getToken } from "@/utils/auth";

export default {
  name: "Order",
  dicts: ['aft_tab', 'sys_common_status', 'aft_stauts', 'aft_kind', 'aft_return_status', 'express_com','return_add'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 售后列表表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //弹框的操作类型 view add edit
      optType: undefined,
      tooltip: '',
      tooltipLoading:false,

      //获取选中的
      selAftReturnStatus: '',
      selAftKind: '',
      selAftTab: '',
      aftKindArr: [],
      aftTabArr: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        aftOrderDate: null,
        aftOrderCode: null,
        aftCode: null,
        aftGoodName: null,
        aftReason: null,
        aftSendCode: null,
        aftReturnAddress: null,
        aftReturnCode: null,
        aftReturnTime: null,
        aftReturnStatus: null,
        aftKind: null,
        aftTab: null,
        aftRemark: null,
        aftStauts: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //快递信息
      express:{
        open: false,
        title: "",
        context: ""
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/user/importData"
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询售后列表列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        aftId: null,
        aftOrderDate: null,
        aftOrderCode: null,
        aftCode: null,
        aftGoodName: null,
        aftPay: null,
        aftReason: null,
        aftSendCom: null,
        aftSendCode: null,
        aftReturnAddress: null,
        aftReturnCom: null,
        aftReturnCode: null,
        aftReturnTime: null,
        aftReturnStatus: null,
        aftKind: null,
        aftReturnPay: null,
        aftCompensatePay: null,
        aftReturnNum: null,
        aftReturnPutNum: null,
        aftTab: null,
        aftRemark: null,
        aftStauts: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.aftId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    //查询物流单号
   fetchData(kind,row) {
      this.express.context = ""
      this.express.title = "快递单号查询中..."
      if(!this.express.open){
        this.express.open = true
        if(kind === 'send'){//发货物流
          setTimeout(() => {
            getQueryTrackReq({"aftSendCom":row.aftSendCom,"aftSendCode":row.aftSendCode}).then(response => {
                 this.express.title = "查询快递单号："+row.aftSendCode;
                 // let str = "<div style='overflow: auto;overflow-x: hidden;max-height: auto;padding: 10px 20px 0;'>" + response.msg + "</div>";
                 this.express.context = response.msg
            });
          }, 1000); // 假设1秒后获取数据
        }else{
          setTimeout(() => {
            getQueryTrackReq({"aftReturnCom":row.aftReturnCom,"aftReturnCode":row.aftReturnCode}).then(response => {
                 this.express.title = "查询快递单号："+row.aftReturnCode;
                 // this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: auto;padding: 10px 20px 0;'>" + response.msg + "</div>", "快递信息", { dangerouslyUseHTMLString: true });
                 this.express.context = response.msg
            });
          }, 1000); // 假设1秒后获取数据
        }

       }
     // if(!this.tooltipLoading){
     //   this.tooltipLoading = false
     //   if(kind === 'send'){//发货物流
     //     setTimeout(() => {
     //       getQueryTrackReq({"aftSendCom":row.aftSendCom,"aftSendCode":row.aftSendCode}).then(response => {
     //            this.tooltip = response.msg;
     //            this.tooltipLoading = true
     //            this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: auto;padding: 10px 20px 0;'>" + response.msg + "</div>", "快递信息", { dangerouslyUseHTMLString: true });

     //            this.$refs.myLink.innerText == "点击查看"
     //       });
     //     }, 1000); // 假设1秒后获取数据
     //   }else{
     //     setTimeout(() => {
     //       getQueryTrackReq({"aftReturnCom":row.aftReturnCom,"aftReturnCode":row.aftReturnCode}).then(response => {
     //            console.log(">>>>",response.msg)
     //            this.tooltip = response.msg;
     //            this.tooltipLoading = true
     //            this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: auto;padding: 10px 20px 0;'>" + response.msg + "</div>", "快递信息", { dangerouslyUseHTMLString: true });

     //            this.$refs.myLink.innerText == "点击查看"
     //       });
     //     }, 1000); // 假设1秒后获取数据
     //   }

     //  }
      // // 模拟异步数据获取

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.optType="add"
      this.open = true;
      this.title = "添加售后列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.optType="edit"
      const aftId = row.aftId || this.ids
      // console.log("dict:",JSON.stringify(this.dict.type))
      const dictType = this.dict.type
      const aftReturnStatusArr = dictType.aft_return_status
      const aftTab = dictType.aft_tab
      getOrder(aftId).then(response => {
      // console.log("response",JSON.stringify(response))
        this.form = response.data;

        //获取选中的
        this.selAftReturnStatus= this.form.aftReturnStatus;
        this.selAftKind=this.form.aftKind;
        this.selAftTab= this.form.aftTab;
        this.open = true;
        this.title = "修改售后列表";
      });
    },
    selectAftReturnStatus(aftReturnStatus){
      console.log("aftReturnStatus:",JSON.stringify(aftReturnStatus))
      const aftKindArr = this.dict.type.aft_kind
      this.aftKindArr = []
      this.form.aftKind = ''
      for (let i = 0; i < aftKindArr.length; i++) {
        console.log("i:",i)
        let item = aftKindArr[i]
        let val = item.value
        console.log("item.value:",item.value)
        if(aftReturnStatus === '买家已发货' && val === "退货退款"){
          this.aftKindArr.push(item)
        }else if(aftReturnStatus === '买家未发货' && (item.label === "未签收仅退款" || item.label === "已签收仅退款")){
           this.aftKindArr.push(item)
        }
      }
      console.log("aftKindArr:",JSON.stringify(this.aftKindArr))

    },
    selectAftKind(aftKind){
      console.log("aftKind",JSON.stringify(aftKind))
      const aftTabArr = this.dict.type.aft_tab
      this.aftTabArr = []
      this.form.aftTab = ''
      for (let i = 0; i < aftTabArr.length; i++) {
        console.log("i:",i)
        let item = aftTabArr[i]
        let val = item.value
        if(aftKind === '退货退款' && (val === '待厂里核实' || val === '待厂里核实，买家退错货' || val === '丢件，月结处理')){
          this.aftTabArr.push(item)
        }
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.aftId != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const aftIds = row.aftId || this.ids;
      this.$modal.confirm('是否确认删除售后列表编号为"' + aftIds + '"的数据项？').then(function() {
        return delOrder(aftIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('aft/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('mes/aft/order/importTemplate', {
      }, `aft_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
